import { BasicColumn, FormSchema } from '@/components/Table'
import { getDeviceChannelList, getDeviceTypeList } from '@/api/collection/device'

export const columns: BasicColumn[] = [
  {
    title: '设备名称',
    dataIndex: 'name',
  },
  {
    title: '设备编码',
    dataIndex: 'code',
  },
  // {
  //   title: '数据获取类型',
  //   dataIndex: 'type',
  //   width: 100,
  // },
  {
    title: '楼栋',
    dataIndex: 'building',
    customRender: ({ record }) => {
      return record?.building?.name || ''
    },
  },
  {
    title: '楼层',
    dataIndex: 'floor',
    customRender: ({ record }) => {
      return record?.floor?.name || ''
    },
  },
  {
    title: '责任部门',
    dataIndex: 'org',
    customRender: ({ record }) => {
      return record?.org?.orgName || ''
    },
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'code',
    label: '设备编码',
    component: 'Input',
    colProps: { span: 6 },
  },
]

export const deviceTypeFormSchema: FormSchema[] = [
  {
    field: 'code',
    label: '类型编码',
    component: 'Input',
    rules: [
      {
        required: true,
      },
    ],
  },
  {
    field: 'nameCopy',
    label: '类型名称',
    component: 'Input',
    required: true,
  },
]
export const recordParamsColumns: BasicColumn[] = [
  {
    title: '参数属性名称',
    dataIndex: 'name',
  },
  {
    title: '单位',
    dataIndex: 'unit',
    customRender: ({ record }) => {
      return record?.unit?.name || ''
    },
  },
]
export const alarmConfigColumns: BasicColumn[] = [
  {
    title: '参数属性名称',
    dataIndex: 'devicePropertyName',
  },
  {
    title: '上限值',
    dataIndex: 'maxValue',
  },
  {
    title: '下限值',
    dataIndex: 'minValue',
  },
  {
    title: '告警类型',
    dataIndex: 'alarmTypeName',
  },
]
export const recordGatherColumns: BasicColumn[] = [
  {
    title: '参数属性名称',
    dataIndex: 'propertyName',
  },
  {
    title: '采集值',
    dataIndex: 'measureValue',
  },
  {
    title: '单位',
    dataIndex: 'unitName',
  },
  {
    title: '采集时间',
    dataIndex: 'measureTime',
  },
]
export const recordAlarmColumns: BasicColumn[] = [
  {
    title: '告警时间',
    dataIndex: 'alarmTime',
  },
  {
    title: '告警设备',
    dataIndex: 'deviceName',
    customRender: ({ record }) => {
      return record?.device?.name || ''
    },
  },
  {
    title: '告警参数',
    dataIndex: 'alarmPropertyName',
  },
  {
    title: '告警类型',
    dataIndex: 'alarmTypeName',
    customRender: ({ record }) => {
      return record?.alarmType?.name || ''
    },
  },
  {
    title: '告警值',
    dataIndex: 'alarmValue',
  },
]

export const addDeviceFormSchema: FormSchema[] = [
  {
    label: '设备编码',
    field: 'code',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入',
    },
  },
  {
    label: '设备名称',
    field: 'name',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入',
    },
  },
  {
    label: '设备类型',
    field: 'type',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      placeholder: '请选择',
      api: getDeviceTypeList,
      labelField: 'name',
      valueField: 'code',
    },
  },
  {
    label: '设备通道',
    field: 'channelId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      placeholder: '请选择',
      api: getDeviceChannelList,
      labelField: 'name',
      valueField: 'id',
    },
  },
]
